package org.ws.lifebacklog;

import java.util.Locale;

import org.ws.lifebacklog.util.AppConfig;
import org.ws.lifebacklog.util.AppExceptionHandler;
import org.ws.lifebacklog.util.Logger;

import android.app.Application;
import android.content.res.Configuration;

public class LifeBacklogApp extends Application {

	private AppConfig mConfig;

	@Override
	public void onCreate() {
		super.onCreate();
		Thread.setDefaultUncaughtExceptionHandler(new AppExceptionHandler());
		setLocale(getConfig().getLanguage());
	}

	private void setLocale(String lang) {
		Logger.d(getClass(), "Set locale: " + lang);
		Locale locale = new Locale(lang);
		Locale.setDefault(locale);
		Configuration configuration = new Configuration();
		configuration.locale = locale;
		getBaseContext().getResources().updateConfiguration(configuration,
				getBaseContext().getResources().getDisplayMetrics());
	}

	public AppConfig getConfig() {
		if (mConfig == null) {
			mConfig = new AppConfig(this);
		}
		return mConfig;
	}
}